Ext.define('PrjAPLean.view.paapply.PaApplyPanel', {
	extend : 'Ext.panel.Panel',
	alias : 'widget.paapplypanel',

	requires : [ 'PrjAPLean.view.paapply.PaApplyPanelViewModel', 
	             'PrjAPLean.view.paapply.PaApplyPanelViewController', 
	             'Ext.form.Panel', 
	             'Ext.form.RadioGroup', 
	             'Ext.form.field.Radio', 
	             'Ext.form.field.Date', 
	             'Ext.toolbar.Toolbar', 
	             'Ext.button.Button', 
	             'Ext.grid.Panel', 
	             'Ext.grid.column.Check', 
	             'Ext.grid.column.Boolean', 
	             'Ext.grid.View', 
	             'Ext.grid.column.Date'
	             ],

	viewModel : {
		type : 'paapplyvm'
	},
	title : 'PA Apply',
	controller : 'paapplyvc',
	closable : true,
	itemId : 'paapplypanel',
	autoScroll:true,
	layout: 'vbox',
	listeners: {
		beforeclose: 'onPanelClose'
	},
	items : [ {
			xtype : 'form',
			layout : 'hbox',
			border : false,
			bodyPadding : 10,
			api : {
				submit : paContro.saveOrUpdatePa
			},
			items : [ {
				xtype : 'container',
				items : [{
							  xtype : 'container',
							  layout : 'vbox',
							  items : [ 
							    {
							    	xtype : 'textfield',
									fieldLabel : 'id',
									name : 'id',
									value:-1,
									hidden : true
								},
							    {
									xtype : 'label',
									style:'font-size:18px;',
									text : '飞利浦（中国）投资有限公司 健康生活部'
								},{
									xtype : 'label',
									style:'font-size:14px;',
									text : 'Philips (China) Investment Co., Ltd. Personal Health'
								} ]
						  },
						  {
						  	  xtype : 'container',
						  	  layout : 'vbox',
						  	  defaults:{
						  		  labelAlign : 'right'
						  	  },
						  	  items : [ {
										xtype : 'displayfield',
										labelWidth : 1000,
										fieldLabel : 'PA #',
										name : 'code'
									},
									{
										xtype : 'displayfield',
										labelWidth : 1000,
										fieldLabel : 'PA submitter',
										value: currentUserName,
										name : 'applier'
									},
									{
										xtype : 'displayfield',
										labelWidth : 1000,
										fieldLabel : 'Date',
										value: Ext.util.Format.date(new Date(), 'Y-m-d')
										//value: Ext.util.Format.date(new Date(), 'Y-m-d H:m')
									}]
						  },
				          {
						xtype : 'fieldset',
						collapsible : false,
						layout : 'vbox',
						items : [ {
									xtype : 'fieldset',
									collapsible : true,
									layout : 'vbox',
									margin:'5',
									width:1100,
									title:'Project Application （PA申请表）',
									items : [ {
										   xtype:'container',
										   layout:'hbox',
										   defaults:{
													labelStyle: 'font-size:12px',
													allowBlank:false,
													labelAlign : 'right',
													labelWidth : 180
											},
											items:[
											     {
											    	xtype : 'textfield',
													fieldLabel : 'Project Name<br>项目名称*',
													name : 'projectName'
												},
										        {
													xtype : 'combobox',
													fieldLabel : 'PA owner<br>项目负责人*',
													name : 'owner',
													editable : false,
													valueField : 'id',
													displayField : 'name'
												},
										        {
													xtype : 'combobox',
													fieldLabel : 'Function<br>申请部门*',
													name : 'function',
													editable : false,
													valueField : 'id',
													displayField : 'name'
												}
										   ]},
										   {
											   xtype:'container',
											   layout:'hbox',
											   defaults:{
														labelStyle: 'font-size:12px',
														allowBlank:false,
														labelAlign : 'right'
												},
												items:[
												     {
												    	xtype : 'textfield',
														fieldLabel : 'Business objectives<br>项目目的*',
														name : 'businessObjective',
														labelWidth : 180
													},
													{
														xtype : 'combobox',
														fieldLabel : 'Activity period<br>计划活动开始期间',
														name : 'startYear',
														itemId : 'startYear',
														editable : false,
														valueField : 'id',
														labelWidth : 180,
														width:270,
														displayField : 'name',
														listeners: {
													    	change: 'onStartYearChange'
													    },
														store: Ext.create('Ext.data.Store',{
					    					            	fields: ['id', 'name'],
					    					                data : [
					    					                    {"id":2016, "name":"2016"},
					    					                    {"id":2017, "name":"2017"},
					    					                    {"id":2018, "name":"2018"},
					    					                    {"id":2019, "name":"2019"},
					    					                    {"id":2020, "name":"2020"},
					    					                    {"id":2021, "name":"2021"},
					    					                    {"id":2022, "name":"2022"},
					    					                    {"id":2023, "name":"2023"},
					    					                    {"id":2024, "name":"2024"},
					    					                    {"id":2025, "name":"2025"},
					    					                    {"id":2026, "name":"2026"}
					    					            ]})
													},
													{
														xtype : 'combobox',
														//fieldLabel : ' ',
														name : 'startMm',
														itemId : 'startMm',
														editable : false,
														style:'margin-top:7px;margin-left:10px;',
														width:75,
														valueField : 'id',
														displayField : 'name',
														listeners: {
													    	change: 'onStartMmChange'
													    },
														store: Ext.create('Ext.data.Store',{
			    	    					            	fields: ['id', 'name'],
			    	    					                data : [
			    	    					                    {"id":1, "name":"01"},
			    	    					                    {"id":2, "name":"02"},
			    	    					                    {"id":3, "name":"03"},
			    	    					                    {"id":4, "name":"04"},
			    	    					                    {"id":5, "name":"05"},
			    	    					                    {"id":6, "name":"06"},
			    	    					                    {"id":7, "name":"07"},
			    	    					                    {"id":8, "name":"08"},
			    	    					                    {"id":9, "name":"09"},
			    	    					                    {"id":10, "name":"10"},
			    	    					                    {"id":11, "name":"11"},
			    	    					                    {"id":12, "name":"12"}
			    	    					            ]})
													},
													{
												    	xtype : 'textfield',
														fieldLabel : 'Activity period<br>计划活动结束期间',
														fieldStyle:'background-color:#DDDDDD;',
								               	   		readOnly:true,
									               	   	labelWidth : 180,
														width:270,
								               	   		itemId : 'endYear',
														name : 'endYear'
													},
													{
														xtype : 'combobox',
														//fieldLabel : ' ',
														name : 'endMm',
														itemId : 'endMm',
														editable : false,
														style:'margin-top:7px;margin-left:10px;',
														width:75,
														valueField : 'id',
														displayField : 'name',
														store: Ext.create('Ext.data.Store',{
			    	    					            	fields: ['id', 'name'],
			    	    					                data : [
																	{"id":1, "name":"01"},
																	{"id":2, "name":"02"},
																	{"id":3, "name":"03"},
																	{"id":4, "name":"04"},
																	{"id":5, "name":"05"},
																	{"id":6, "name":"06"},
																	{"id":7, "name":"07"},
																	{"id":8, "name":"08"},
																	{"id":9, "name":"09"},
																	{"id":10, "name":"10"},
																	{"id":11, "name":"11"},
																	{"id":12, "name":"12"}
			    	    					            ]})
													}
										   ]},
										   {
											   xtype:'container',
											   layout:'hbox',
											   defaults:{
														labelStyle: 'font-size:12px',
														allowBlank:false,
														labelAlign : 'right',
														labelWidth : 180
												},
												items:[
												     {
												    	xtype : 'textfield',
														fieldLabel : 'Applier<br>项目申请人*',
														fieldStyle:'background-color:#DDDDDD;',
								               	   		readOnly:true,
								               	   		value: currentUserName,
														name : 'applier'
													},
													{
														xtype : 'combobox',
														fieldLabel : 'Activity group<br>活动大类*',
														name : 'fundingGroupId',
														editable : false,
														valueField : 'id',
														displayField : 'name'
													}
										   ]},
										   {
											   xtype:'container',
											   margin:'10 0 10 0',
											   layout:'hbox',
											   defaults:{
													labelStyle: 'font-size:12px',
													allowBlank:false,
													labelAlign : 'right',
													margin:'',
													labelWidth : 180
												},
												items:[
									   	        {
									   	        	xtype : 'textarea',
													fieldLabel : 'Description<br>针对活动类型的进一步表述，如新品上市，品牌提升，渠道拓展等*',
													name : 'description',
													width:710
									   	        }
										   ] }
									]
								   },
								   {
									    xtype : 'fieldset',
										collapsible : true,
										layout : 'vbox',
										margin:'5',
										width:1100,
										title:'填写Activity及对应金额',
										items : [{
											   xtype:'container',
											   layout:'hbox',
											   margin:'10 0 10 0',
											   defaults:{
														labelStyle: 'font-size:12px',
														allowBlank:false,
														labelAlign : 'right',
														labelWidth : 180
												},
												items:[
												     {
														xtype : 'combobox',
														fieldLabel : 'Activity*',
														name : 'activityGroupId',
														itemId : 'activityGroupId',
														editable : false,
														valueField : 'id',
														displayField : 'name'
													 },
											         {
														xtype : 'combobox',
														fieldLabel : 'Channel*',
														name : 'channelId',
														itemId : 'channelId',
														editable : false,
														valueField : 'id',
														displayField : 'name'
													 },
											         {
														xtype : 'button',
														text : '添加',
														style:'margin-left:20px;',
														iconCls: 'common_icon_save',
														handler : 'onAddActivityClick'
													 }
											]}     
										]
								   },
								   {
									    xtype : 'fieldset',
										collapsible : true,
										layout : 'vbox',
										margin:'5',
										width:1100,
										title:'Activity分配明细',
										items : [{
								        	  xtype : 'container',
								        	  layout : 'vbox',
								        	  margin:'5',
								        	  items : [ {
														xtype : 'toolbar',
														dock : 'top',
														border : 0,
														layout : {
															type : 'hbox'
														},
														items : [ 
															{
																xtype : 'button',
																iconCls : 'common-icon-delete',
																text : 'Delete',
																listeners : {
																	click : 'onDelActivityClick'
																}
															},
															{
																xtype : 'button',
																text : 'Allocation',
																icon : 'images/refresh.png',
																handler : 'onActivityAllocationClick'
															}
													   ]},
								        	            {
															xtype : 'gridpanel',
															itemId : 'activityGrid',
															reference : 'activityGrid',
															width:1000,
															autoScroll : true,
															bind : '{leanProjectLines}',
															viewConfig : {
																enableTextSelection : true
															},
															columns : [ 
															{
																xtype : 'gridcolumn',
																width:100,
																text : '序号',
																labelAlign : 'right',
																name : 'id',
																dataIndex : 'id'
															}, 
															{
																xtype : 'gridcolumn',
																width:260,
																text : 'Activity',
																labelAlign : 'right',
																name : 'activityGroupId',
																dataIndex : 'activityGroupId'
															},
															{
																xtype : 'gridcolumn',
																width:260,
																text : 'Channel',
																labelAlign : 'right',
																name : 'channelId',
																dataIndex : 'channelId'
															}, 
															{
																xtype : 'gridcolumn',
																width:260,
																text : 'Amount',
																labelAlign : 'right',
																name : 'amount',
																dataIndex : 'amount'
															}
														] 
												}],
									            dockedItems: [{
						        			        xtype: 'pagingtoolbar',
						        			        dock: 'bottom',
						        			        bind: {
						        				        store: '{leanProjectLines}'
						        				    },
						        			        displayInfo : true,
						        					displayMsg:'显示 {0} - {1}条记录，总共 {2}条记录',
						        					emptyMsg:'暂无数据',
						        					beforePageText:'页数',
						        					afterPageText:'总共{0}页',
						        					firstText:'第一页',
						        					prevText:'上一页',
						        					nextText:'下一页',
						        					lastText:'最后一页',
						        					width:'100%',
						        					emptyMsg : '没有记录'
									            }]
									    },     
										]
								   },
								   {
									    xtype : 'fieldset',
										collapsible : true,
										layout : 'vbox',
										margin:'5',
										width:1100,
										title:'Promotion KPI',
										items : [{
									        	  xtype : 'container',
									        	  layout : 'vbox',
									        	  margin:'5',
									        	  defaults:{
									        		  labelAlign : 'right',
									        		  labelWidth : 180
									        	  },
									        	  items : [
												  {
												    	xtype : 'textfield',
														fieldLabel : 'Sell-in related',
														name : 'sellinKpi'
												  },
												  {
												    	xtype : 'textfield',
														fieldLabel : 'Sell-out related',
														name : 'selloutKpi'
												  },
												  {
												    	xtype : 'textfield',
														fieldLabel : 'Market share related',
														name : 'marketShareKpi'
												  }
									        	  ]
									    	}
										]
								   }
							]
			        } ]
			} ]
	} ],
	buttons : [ 
		{
			xtype : 'button',
			text : '保存',
			width : 150,
			iconCls: 'common_icon_save',
			itemId: 'saveButton',
			handler : 'onPaApplyClick'
		},{
			xtype : 'button',
			text : '提交',
			iconCls: 'common_icon_save',
			width : 150,
			itemId: 'saveAndSubButton',
			handler : 'onSaveAndSumitClick'
		}
	]
});
